package dd.control;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import xml.Message;

import dd.model.Event;
import dd.model.Model;
import dd.view.AdminScreen;

public class ReportRequestController implements ActionListener {

	private AdminScreen adminScreen;
	private Event event;

	public ReportRequestController(AdminScreen adminScreen, Event event) {
		this.adminScreen = adminScreen;
		this.event = event;
	}

	@Override
	public void actionPerformed(ActionEvent e) { // this action is performed by admin
		Model.getInstance().setAdminScreen(this.adminScreen);

		// get the selected item
		String selectedEvent = this.adminScreen.getSelectetEvent();

		if (selectedEvent == null) { // if the selected item is null, return to select
			// alert, message
			adminScreen.getLblErrorMessage().setVisible(true);
		} else { // else create the report under the event id
			adminScreen.getLblErrorMessage().setVisible(false);
			String eventId = selectedEvent.split(":")[0].trim();

			System.out.println(Model.getInstance().getEvent().getedgelist().size());

			// send the event id which wants to generate the report
			String xmlString = Message.requestHeader() + "<reportRequest key='" + eventId + "'></reportRequest>"
					+ "</request>";
			Model.getInstance().getServerAccess().sendRequest(new Message(xmlString));
		}
	}

}
